Common
api.ledControl(state)
- Overview
- Arguments
- Example
Turns ON or OFF the on board LED. It can be also used for debugging purposes.
- state (integer) - sets LED state (1=ON, 0=OFF)
--turns on blue LED
api.ledControl(1)
api.delayms(ms,mode)
- Overview
- Arguments
- Example #1
- Example #2
- Example #3
Pause the execution for ms milliseconds.
- ms (integer) - The number of milliseconds to delay (in range from 0 to 2147483647)
- mode (integer)(optional) - use sleep in longer intervals:
- 1 - if the interval ms is longer than 10 ms, sleep
- 2 - sleep for defined amount of milliseconds
api.delayms(1000) --delay one second
api.ledControl(1) -- turn on blue LED
api.delayms(1000) -- wait 1 second
api.ledControl(0) -- turn off blue LED
api.delayms(1000,2) -- sleep for one second, then continue in the process
api.randInt(min, max)
- Overview
- Arguments
- Return
- Example
Generate random number within given range.
Available only for LoRaWAN devices (function uses it's module to generate random number)
- min (integer) - beginning number of the interval (in range from 0 to 2147483647)
- max (integer) - end number of the interval (in range from 0 to 2147483647)
- number (Integer)
-- generates random number within interval from 5 to 20
ran=api.randInt(5, 20)
api.getUniqueNumber()
- Overview
- Return
- Example
Calling this function increases uint32_t variable by one every time this function is called then it returns it's value. It's in range (in range from 0 to 2^32)*
- num (integer) - Unique number (in range from 0 to 2^32)*
--get an unique number
num = api.getUniqueNumber()
api.getBatteryVoltage()
- Overview
- Return
- Example
Get curent battery voltage in mV.
- voltage (Integer)
--get battery voltage value in mV
mv = api.getBatteryVoltage()
api.getTick(int)
- Overview
- Arguments
- Return
- Example
Returns current number of milliseconds since startup. Counts up to 2^32 and then restarts from 0. By default it's using RTC derived tick which is incremented during sleep, but it's possible to explicitly select systick, which isn't.
- int (integer) (optional)
- 2 to use RTC derived tick and return value in seconds
- 1 to use RTC derived tick and return value in ms (default)
- 0 to use systick (value in ms)
- int (integer) (optional) (if first argument is 0)
- 1 - reset systick value to 0
- 0 - do not reset the systick (default)
- tick (integer) - Value according to argument (in seconds / milliseconds)
--get a timestamp, can be used for timing
timestamp = api.getTick()
-- to show the amount of milliseconds you can use print() function
print(timestamp)
api.dumpArray(str, opt)
- Overview
- Arguments
- Example
Prints contents of variable as hexadecimal string (dumps array into console)
- str (string) - variable to print
- opt (string)(optional) - optional argument defining type of print
- "normal" - printing method used by default
- "raw" - prints only the raw values
--print string "123ef" as hexadecimal
api.dumpArray("123ef")
-- output
-- 00 : 31 32 33 65 66
--print string "123ef" as hexadecimal raw
api.dumpArray("123ef","raw")
-- output
-- 31 32 33 65 66
api.float(op,form,arg1,arg2)
- Overview
- Arguments
- Return
- Example #1
- Example #2
- Example #3
Performs operation with given floating point data.
Only if it's allowed by the firmware. Convert function available from FW version v2.5.1
-
op (string) - The operation to perform (“add” - addition, “sub” - substraction of arg2 from arg1, “mul” - multiplication, “div” - division of arg1 by arg2, “coerce” - coercion, unary operation using only arg1, “convert” - conversion of integer to float, unary operation using only arg1)
-
form (string) - Two or three characters specifying the format of input/output data.
- first position is for arg1.
- second either specifies the format of arg2 or if last, specifies the format of return data, which are the same
- by adding “N” to end of a string it coerces and returns little endian integer (OPTIONAL)
-
arg1 (string) - The first operation argument, formated as specified in format.
-
arg2 (string) - The second operation argument, formated as specified in format.
- result (string, integer) - Returns result of operation, either 4 bytes little/big endian (depends on form parameter) IEEE 754 float or string float representation or integer value
-- Multiply IEE 754 float with a floating point constant and return coerced value
-- S - string float representation, e.g. “2.234”
-- B - binary little endian IEEE 754 representation as 4 characters/bytes in a string
ret = api.float("mul", "SSN", "12.8", "1000.0")
print(ret)
-- output = 12800
ret = api.float("mul", "SSS", "12.8", "1000.0")
print(ret)
-- output = 12800.0000
-- hexadecimal interpretation of a number 12.8 is 0x414CCCCD (IEE 754)
x=string.char(0xCD,0xCC,0x4C,0x41)
ret = api.float("mul", "BSS", x, "1000.0")
print(ret)
-- output = 12800.0000
-- Convert integer to IEE 754 float
-- N - Input in little endian integer(for convert only)/Returns ouput as little endian integer
-- I - Binary little endian integer representation as 4 characters/bytes in a string(for convert only).
-- B - binary little endian IEEE 754 representation as 4 characters/bytes in a string
-- > - returns result as big endian, if used as output IEEE 754 representation as 4 characters/bytes in a string
-- < - returns result as little endian, if used as output IEEE 754 representation as 4 characters/bytes in a string (default value)
y=string.char(0xCD,0xCC,0x4C,0x42)
ret = api.float("convert", "IB", y)
api.dumpArray(ret)
-- output = 9A 99 84 4E
y=125
ret = api.float("convert", "NB>", y)
api.dumpArray(ret)
-- output = 42 FA 00 00
api.setVar(index, value, bool)
- Overview
- Arguments
- Example
- Example (string)
Saves a persistent variable value, can be used between different wake up iterations.
- index (integer) - Index of the variable to write, index 0 to 15 is available for RAM variables (lost on reset), index 16 to 47 for High Endurance EEPROM (HEE) variables (6.4M writes) and index 48 to 1071 is available for variables stored in EEPROM (100k writes).
- value (integer) - Value to store at index (in range from 0 to 2147483647)
- bool (boolean)(optional) - Optional argument, which stores bitwise negation of stored value into address higher by one
OR
- mode (string) - explicit memory mode, currently "bytes" mode supported
- value (string) - string array buffer to write
--set persistent variable value from index 1000 to value of 3424
--can be used to send different data between wake-ups
--for variables persistent between device reset,
--use indexes 48 to 1071
api.setVar(1000, 3424)
myVariable = "This is some string to store to eeprom"
api.setVar(29, #myVariable) -- save the length for later readout
api.setVar(30, "bytes", myVariable) -- consumes in total ceil(#myVariable / 4) 32-bit indexes in EEPROM/RAM/HEE
api.getVar(index)
- Overview
- Arguments
- Returns
- Example
- Example (string)
Returns persistent variable value, can be used between different wake up iterations.
- index (integer) - Index of the variable to read, 0 to 15 is available for RAM variables (lost on reset), 16 to 47 for High Endurance EEPROM (HEE) variables (6.4M writes) and 48 to 1071 is available for variables stored in EEPROM (100k writes).
- default (integer)(optional) - Default value, which is returned if value stored in the address is same as bitwise negation of value stored in address higher by one
OR
- mode (string) - Mode to use, currently supported "bytes"
- length (int) - Length in bytes to read
- value (integer)(string) - Value of the 32bit variable, or string.
--get persistent variable value from index 1000
--can be used to send different data between wake-ups
--for variables persistent between device reset,
--use indexes 48 to 1071
slotNumber = api.getVar(1000)
stringLength = api.getVar(29)
myReadout = api.getVar(30, "bytes", stringLength)
print(myReadout) -- should print "myVariable" content!